package com.zjw.hyphenateui.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.example.havi.helper.ChatHelper;
import com.example.havi.ui.ChatActivity;
import com.zjw.hyphenateui.R;
import com.zjw.hyphenateui.util.InputMethodUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class SearchChatFragment extends BaseFragment {
    @BindView(R.id.chat_id_tv)
    EditText chatIdTv;
    @BindView(R.id.confirm_tv)
    TextView confirmTv;
    Unbinder unbinder;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_search_chat;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.confirm_tv)
    public void onViewClicked() {
        InputMethodUtils.hideSoftInput(chatIdTv);
        String chatId = chatIdTv.getText().toString();
        if(TextUtils.isEmpty(chatId)){
            showToast("请输入对方的聊天id");
            return;
        }

        if(chatId.equals(ChatHelper.getInstance().getHyChatUser().getChatUserName())){
            showToast("不能与自己聊天！！");
            return;
        }

        //跳转聊天
        ChatActivity.startActivity(getActivityContext(),chatId,chatId,chatId,chatId);
    }
}
